package de.gof.ppstool.util;

import java.io.Serializable;
import java.util.Locale;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

@ManagedBean(name = SpracheControllerBean.NAME)
@SessionScoped
public class SpracheControllerBean implements Serializable {
	private static final long serialVersionUID = 1986565724093259408L;
	public static final String NAME = "sprache";
	private Locale locale;

	/** 
	 */

	public SpracheControllerBean() {
		super();
	}

	/** 
	 */

	public Locale getLocale() {
		return locale;
	}

	/** 
	 */

	@Override
	public String toString() {
		return "{locale=" + locale + "}";
	}

	/** 
	 */

	public String englisch() {
		locale = Locale.ENGLISH;
		set();
		return null;
	}

	/** 
	 */

	public String deutsch() {
		locale = Locale.GERMAN;
		set();
		return null;
	}

	/** 
	 */

	private String set() {
		final FacesContext ctx = FacesContext.getCurrentInstance();
		ctx.getViewRoot().setLocale(locale);
		ctx.renderResponse();
		return null;
	}

	/**
	 * F&uuml;r den Aufruf bei "f:view locale=#{sprache.aktuell}"
	 */
	public Locale getAktuell() {
		if (locale != null)
			return locale;

		final FacesContext ctx = FacesContext.getCurrentInstance();
		final Locale requestLocale = ctx.getExternalContext()
				.getRequestLocale();
		return requestLocale;
	}

}
